package com.vsoft.sms_cm;
//用于数据处理
import java.io.DataOutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.Configuration;
import com.vsoft.framework.core.db.DBGadgets;
import com.vsoft.framework.core.db.DBTrans;
import com.vsoft.framework.core.db.OperAgent;
import com.vsoft.framework.core.db.SQLArgs;
import com.vsoft.framework.core.esb.ServiceBus;
import com.vsoft.framework.core.util.BOHelper;
import com.vsoft.framework.core.util.LogCollect;
import com.vsoft.framework.core.util.XMLUtil;
import com.vsoft.framework.server.servlet.SessionData;
import com.vsoft.framework.server.servlet.HttpUtil;
import com.vsoft.anti_fra.*;

public class TestCRM {

	private static Logger vLogger = Logger.getLogger(TestQuery.class);
	private static String vName = TestCRM.class.getName();
	private SessionData vSD = null;
	private String vDebugHome = "";
	private BusiObj				vInBO		=  new BusiObj();
	private SQLArgs			vArg				= new SQLArgs();
	
	public static void main(String[] args)  {
	
		try{

			vLogger.info("---------------InitSystem-------------");
			Configuration.InitSystem();
			vLogger.info("---------------generate test data-------------");

			TestCRM t = new TestCRM();
			Connection conn = DBTrans.getConnection();
			String listName=	"RESULT";
			
			String sql	=	" select * from log_bizsf where order_num=:order_num and area_no=:area_no " +
								" and log_time>sysdate -3 and log_state=-1";
			String order_num=args[0];
			String area_no=args[1];
			t.vArg.reset();
			//
			t.vArg.setArg("order_num", order_num);
			t.vArg.setArg("area_no", area_no);
			BusiObj rsBo 						= OperAgent.execQuery(conn, "Query log_info " ,sql, t.vArg);
		    vLogger.info("查询log，返回数据是:\n" + BOHelper.boToXML(rsBo));
		    ArrayList<BusiObj> Al_area = rsBo.getBusiObjList(listName);
		    int size=Al_area.size();
		    if(size==0)//
		    {
		    	throw new BaseException("错误","根据号码"+order_num+"在日志中找不到信息");
		    }
		    else 
		    {
		    	t.vInBO=Al_area.get(0);
		    }


			vLogger.info("失败订购号码信息:\n order_num :" +order_num+"\n last area_no :"+ BOHelper.boToXML(t.vInBO));
			t.vInBO.delete("UPDATE_LOG_TIME");
			t.vInBO.delete("LOG_TIME");
			t.vInBO.delete("LOG_BIZSF_SN");
			t.vInBO.delete("LOG_STATE");
			t.vInBO.delete("LOG_DESC");
			
			
			/////////////////////////////////////////////////////////////////
/*			t.vInBO.setString("cust_name", "interface test");
			t.vInBO.setString("mobile_num", "1212");
			t.vInBO.setString("phone_num", "");

			t.vInBO.setString("area_no", "0564");

			t.vInBO.setString("email", "");
			t.vInBO.setString("fax", "");
			t.vInBO.setString("address", "interface test");
			//t.vInBO.setString("log_name", "xxx");
			//t.vInBO.setString("password", "123");
			t.vInBO.setString("postcode", "430101");
			t.vInBO.setString("new_flag", "1");
			t.vInBO.setString("order_no", "10566213");
			t.vInBO.setString("offer_id", "10023");
			t.vInBO.setString("offer_name", "基础版");
			t.vInBO.setString("order_num", "2610111");//2288888   3659663   2288888-2
			t.vInBO.setString("order_time", "");
			t.vInBO.setString("eff_date", "");
			t.vInBO.setString("exp_date", "");
			t.vInBO.setString("notes", "ssssssss");*/
			t.vInBO.setName("BizSF");
			t.vInBO.setString("SESSION_STAFF_NO", "999");
			vLogger.info("xml是:\n\n\n\n" + BOHelper.boToXML(t.vInBO));
			/////////////////////////////////////////////call service
			//t.vInBO.setString("new_flag", "1");
			t.vInBO.setConnection(conn);

			t.vInBO.setString("debugSee", "1");
			BusiObj retBo					=		ServiceBus.runService(t.vInBO);
			DBGadgets.check(conn);
			conn.rollback();
			//conn.commit();
			conn.close();
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));

			//////////////////////////////

		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		catch(BaseException e)
		{
			e.printStackTrace();
			vLogger.error(e.ErrMethod);
			vLogger.error(e.SysMsg);
		}
			vLogger.info("---------------Game Over-------------");
	}	
	
		

	private int  init()
	{
		int iRet = 0;
		vSD = new  SessionData();
		vSD.vRoleCode = new String[] {"1"};
		vSD.vStaffCode = "1";
		vSD.vStaffNo = "0001";
		vSD.vStaffName = "test";
		
	
		vDebugHome = System.getProperty("DEBUG_HOME");
		if (vDebugHome == null)
		{
			iRet = -1;
			vLogger.error("需要设置DEBUG_HOME环境变量来指定debug 文件所在的目录");
		}
		return iRet;
		
	}
	
}
